import httpCreator from '../assets/js/common-http'
let http = httpCreator()

// 获取企业信息
function siteinfo () {
  return new Promise((resolve, reject) => {
    http.get('/siteinfo').then(resolve).catch(reject)
  })
}

// 获取轮播图
function focus () {
  return new Promise((resolve, reject) => {
    http.get('/focus').then(resolve).catch(reject)
  })
}

// 获取合作伙伴
function partner () {
  return new Promise((resolve, reject) => {
    http.get('/partner').then(resolve).catch(reject)
  })
}

// 获取企业荣誉
function honor () {
  return new Promise((resolve, reject) => {
    http.get('/honor').then(resolve).catch(reject)
  })
}

// 获取产品分类
function productcate () {
  return new Promise((resolve, reject) => {
    http.get('/procate').then(resolve).catch(reject)
  })
}

// 获取产品分页数据
function productpagedata (params, query) {
  let url = '/pageproduct'
  if (query && query.cateId) { // 是否传递了产品类别的id
    url += `/${query.cateId}`
  }
  return new Promise((resolve, reject) => {
    http.post(url, params).then(resolve).catch(reject)
  })
}

// 获取滚动产品
function scrollproduct (top = 8) {
  return new Promise((resolve, reject) => {
    http.get(`/topproduct/${top}`).then(resolve).catch(reject)
  })
}

// 获取产品详情
function productdetail (id) {
  return new Promise((resolve, reject) => {
    http.get(`/productdetail/${id}`).then(resolve).catch(reject)
  })
}

export default {
  siteinfo,
  focus,
  partner,
  honor,
  productcate,
  productpagedata,
  scrollproduct,
  productdetail
}
